package com.example.fan.airline_reservation;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.ashokvarma.bottomnavigation.ShapeBadgeItem;
import com.example.fan.airline_reservation.fragment_class.ac_add_fights;
import com.example.fan.airline_reservation.fragment_class.ac_modify_fight;
import com.example.fan.airline_reservation.fragment_class.ac_statistic;

import static com.ashokvarma.bottomnavigation.BottomNavigationBar.BACKGROUND_STYLE_RIPPLE;
import static com.ashokvarma.bottomnavigation.BottomNavigationBar.MODE_FIXED;

public class AC_Interface extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ac__interface);

        /*隐藏title*/
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }

        /*底部导航栏相关操作！！！！！*/
        BottomNavigationBar mBottomNavigationBar= (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
        mBottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED)
                .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);

        mBottomNavigationBar
                .setActiveColor(R.color.black)//选中颜色 图标和文字
//                .setInActiveColor("#8e8e8e")//默认未选择颜色
                .setBarBackgroundColor(R.color.white);//默认背景色
        ShapeBadgeItem mShapeBadgeItem = new ShapeBadgeItem()
                .setShapeColorResource(R.color.lawngreen)
                .setGravity(Gravity.TOP | Gravity.END)
                .setHideOnSelect(false);
        mBottomNavigationBar
                .addItem(new BottomNavigationItem(R.drawable.home,"添加航班")
                        .setInactiveIcon(ContextCompat.getDrawable(AC_Interface.this,R.drawable.home))
                        .setBadgeItem(mShapeBadgeItem))
                .addItem(new BottomNavigationItem(R.drawable.home,"修改航班")
                        .setInactiveIcon(ContextCompat.getDrawable(AC_Interface.this,R.drawable.home)))
                .addItem(new BottomNavigationItem(R.drawable.me,"我的")
                        .setInactiveIcon(ContextCompat.getDrawable(AC_Interface.this,R.drawable.me)))
                .setFirstSelectedPosition(0)//设置默认选择的按钮
                .initialise();//所有的设置需在调用该方法前完成
        replaceFragment(0);//默认选择第一个
        /*底部导航栏监听*/
        mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override/*选中切换*/
            public void onTabSelected(int position) {
                replaceFragment(position);
            }

            @Override/*上一次选中，我不做任何处理*/
            public void onTabUnselected(int position) {

            }

            @Override/*重复选中同一个，我也不做处理*/
            public void onTabReselected(int position) {

            }
        });



    }

    /*替换碎片中的内容*/
    private void replaceFragment(int position){
        Fragment fragment=null;
        switch (position){
            case 0:
                fragment=new ac_add_fights();
                break;
            case 1:
                fragment=new ac_modify_fight();
                break;
            case 2:
                fragment=new ac_statistic();
                break;
            default:
                break;
        }
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.AC_fragment,fragment);
        transaction.commit();
    }


}
